"""
This module contains some little helper functions
and definitely need some more checks for the future. 
"""

"""
    This file is part of project webCA

    webCA is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    webCA is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with webCA. If not, see <http://www.gnu.org/licenses/>.
"""

import os

def make_folder(folder):
    """This function looks for the existence of a folder, if it is not
    there it gets created"""
    if (os.path.exists(folder) and os.path.isdir(folder)):
        print 'folder "%s" is already there' % folder
    else:
        print 'creating folder "%s"' % folder
        os.mkdir(folder)

def make_file(file):
    """This function looks for the existence of a file, if it is not
    already there it gets created"""
    if (os.path.exists(file) and os.path.isfile(file)):
        print 'file "%s" is already there' % file
    else:
        print 'touching file "%s"' % file
        open(file, 'w').close()

def build_subject(country, state, location, organisation, organisation_unit, common_name, email_address):
    """Tiny helper function to build the distinguished name"""
    return  '/C=' + country + \
            '/ST=' + state + \
            '/L=' + location + \
            '/O=' + organisation + \
            '/OU=' + organisation_unit + \
            '/CN=' + common_name + \
            '/emailAddress=' + email_address

